package spark.network;

import spark.network.protocol.Base;

import java.net.SocketException;

import org.apache.log4j.Logger;

public class ServerSender extends Sender {
	private static Logger logger = Logger.getLogger(ServerSender.class);

	protected ActiveClientList clients;

	public ServerSender(int port, ActiveClientList clients) throws SocketException {
		super(port);
		this.clients = clients;
	}

	public ServerSender(ActiveClientList clients) throws SocketException {
		super();
		this.clients = clients;
	}

	/**
	 * Propagates a packet to all known and authorized network clients using the {@link ServerSender#send(spark.network.protocol.Base, java.net.InetSocketAddress) send} method.
	 * If an {@code exludedPlayer} is provided he is the only authorized client who does not receive the response.
	 * This parameter can utilized if this specific player has already received an individual, more detailed response.
	 *
	 * @param packet         Packet to propagate
	 */
	public void propagate(Base packet) {
		for(NetworkConnection c : clients.getAuthorizedClients()) {
			send(packet, c);
		}
	}
}
